package com.example.hotel_lxy.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hotel_lxy.R;
import com.example.hotel_lxy.bean.BeanBean;
import com.example.hotel_lxy.bean.DialogHIstoryBean;
import com.example.hotel_lxy.net.Api;
import com.example.hotel_lxy.utils.SPUtils;
import com.example.hotel_lxy.view.SaveBitmap;
import com.example.hotel_lxy.wxapi.WXShare;
import com.ysxsoft.common_base.base.RBaseAdapter;
import com.ysxsoft.common_base.base.RViewHolder;
import com.ysxsoft.common_base.utils.DisplayUtils;
import com.ysxsoft.common_base.utils.JsonUtils;
import com.ysxsoft.common_base.utils.ToastUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import okhttp3.Call;


/**
 * 分享 保存图片
 * create by Sincerly on 9999/9/9 0009
 **/
public class ShareDialog extends Dialog {
    private Context mContext;
    private TextView wechat;
    private TextView wechatfriend;
    private TextView picture;
    private TextView cancel;

    static  String url;
    static String type;
    private static  Bitmap bmp;
    private WXShare wxShare;
    private static String data;
    public ShareDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
    }

    private View init() {
        View view = View.inflate(mContext, R.layout.dialog_share, null);
        wxShare = new WXShare(mContext);
        wechat=view.findViewById(R.id.wechat);
        wechatfriend=view.findViewById(R.id.wechatfriend);
        picture=view.findViewById(R.id.picture);
        if(type.equals("1")){
            picture.setVisibility(View.GONE);
        }else{
            picture.setVisibility(View.VISIBLE);
        }
        wechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                if(type.equals("1")){
////                    wxShare.shareText("客户，您好！已为您预订"+data+"\n" +
////                            "电话：0471-4166176\n" +
////                            "地址：呼和浩特如意开发区满洲里南路东岸国际东区。");
//                    wxShare.share("https://www.baidu.com/?tn=98010089_dg&ch=2","鹿小乙","测试",mContext,0);
//                }else{
                    wxShare.WxBitmapShare(mContext,bmp,0);
//                }
                dismiss();
            }
        });
        wechatfriend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                if(type.equals("1")){
////                    wxShare.shareText("客户，您好！已为您预订"+data+"\n" +
////                            "电话：0471-4166176\n" +
////                            "地址：呼和浩特如意开发区满洲里南路东岸国际东区。");
//                    wxShare.share("https://www.baidu.com/?tn=98010089_dg&ch=2","鹿小乙","测试",mContext,0);
//                }else{
                    wxShare.WxBitmapShare(mContext,bmp,2);
//                }
                dismiss();
            }
        });

        picture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onPositiveClick("2");
                dismiss();
            }
        });
        cancel=view.findViewById(R.id.cancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        return view;
    }




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCanceledOnTouchOutside(true);
//        setCancelable(false);
        setContentView(init());
    }

    public void showDialog() {
        if (!isShowing()) {
            show();
            WindowManager.LayoutParams lp = getWindow().getAttributes();
//            lp.height = DisplayUtils.getDisplayWidth(mContext) * 5 / 5;
            lp.width = DisplayUtils.getDisplayWidth(mContext) * 10 / 10;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            getWindow().setAttributes(lp);
            getWindow().setGravity(Gravity.BOTTOM);
        }
    }

    public static ShareDialog show(Context context, OnDialogClickListener listener,String urls,String types,Bitmap bmps,String datas) {
        ShareDialog dialog = new ShareDialog(context, R.style.BottomDialogStyle);
        dialog.setListener(listener);
        url=urls;
        type=types;
        bmp=bmps;
        data=datas;
        dialog.showDialog();
        return dialog;
    }

    public OnDialogClickListener listener;

    public ShareDialog setListener(OnDialogClickListener listener) {
        this.listener = listener;
        return this;
    }

    public interface OnDialogClickListener {
        /**
         * 点击确定按钮事件
         */
        public void onPositiveClick(String s);
    }


}